﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LIUS.Beta.FileSystem.PathFileSuffix;

namespace KopainConcept.Schemas
{

    partial class ConceptRoot
    {

        /// <summary>This getter sets the ID as a proper Guid; not as the string "id" uses.
        /// </summary>
        public Guid IDAsGuid { get { return new Guid(this.id); } }

        /// <summary>Got to have a defautl root to keep MSs serialization working.
        /// </summary>
        [Obsolete( "Please the constructor that takes all necessary arguments instead.", false )]
        public ConceptRoot()
        {
            id = Guid.NewGuid().ToString();
        }

        /// <summary>This constructor takes all mandator parameters.
        /// We avoid creating the ID internally and retrieving the Formatversion since this source is just an xml document and we don't want it to have too big responsibilities.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="formatVersion"></param>
        private ConceptRoot( Guid id, int formatVersion )
#pragma warning disable 618,612
            :this()
#pragma warning restore 618,612
        {
            this.id = id.ToString();
            this.formatVersion = formatVersion;
        }

        /// <summary>This constructor creats a new Concept.  
        /// We avoid creating the ID internally and retrieving the Formatversion since this source is just an xml document and we don't want it to have too big responsibilities.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="formatVersion"></param>
        /// <returns></returns>
        internal static ConceptRoot CreateNew( Guid id, int formatVersion)
        {
            ConceptRoot ret = new ConceptRoot(id, formatVersion);
            ret.Note = Schemas.NoteType.AllocateArray(0);   // No Notes persisted..
            return ret;
        }

    }

    partial class NoteType
    {

        /// <summary>This property handles the ID as a proper Guid; not as the string "id" uses.
        /// </summary>
        public Guid IDAsGuid { get { return new Guid(this.id); } }

        /// <summary>The default constructor must exist to make the serialization work.
        /// </summary>
        public NoteType()
        {
        }

        /// <summary>This constructor takes all necessary parameters.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="title"></param>
        /// <param name="filenameSuffix"></param>
        /// <param name="cursorPosition"></param>
        internal NoteType( Guid id, string title, FilenameSuffix filenameSuffix, int cursorPosition)
        {
            System.Diagnostics.Debug.Assert(null != id);
            System.Diagnostics.Debug.Assert(null !=title);
            System.Diagnostics.Debug.Assert(null != filenameSuffix);
            System.Diagnostics.Debug.Assert(cursorPosition >= 0);
            this.id = id.ToString();
            this.title = title;
            this.file = filenameSuffix.ToString();
            this.cursorPosition = cursorPosition;
        }

        /// <summary>This method creates a new array of NoteType.  Note: only the array is allocated - not the NoteType objects.
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        internal static NoteType[] AllocateArray(int length)
        {
            System.Diagnostics.Debug.Assert(length >= 0);
            return new NoteType[length];
        }

    }

}
